package com.tom.web.controller;

import com.tom.dto.SMSDto;
import com.tom.service.VerfycodeService;
import com.tom.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerfycodeController {
    @Autowired
    private VerfycodeService verfycodeService;

    /**
     * 获取图片验证码
     * @param key
     * @return
     */
    @RequestMapping(value = "/imageCode/{key}", method= RequestMethod.GET)
    public AjaxResult getImgCode(@PathVariable("key") String key){
        return AjaxResult.me().setResultObj(verfycodeService.getImgCode(key));
    }

    /**
     * 获取短信验证码
     * @param dto
     * @return
     */
    @RequestMapping(value = "/sendSmsCode", method= RequestMethod.POST)
    public AjaxResult getSMSCode(@RequestBody SMSDto dto){
        verfycodeService.getSMSCode(dto);
        return AjaxResult.me();
    }
}
